﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateWeldPoint.CApCreateWpTCLogic
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Resources;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.CreateWeldPoint;

internal class CApCreateWpTCLogic
{
  private const string _WELD_POINT_REVISION_SUBTYPE = "WeldPointRevision";
  public const string _CREATE_WELD_POINTS_MODE_COMMAND_ID = "GraphicViewerModes.ModeCreateWeldPoint.1";
  public CApCreateWpCommonValidator WeldContainerValidator;
  public TxCompositeValidator _CompositeWeldContainerValidator;
  public CApCreateWpCommonValidator WeldOperationValidator;
  public TxCompositeValidator _CompositeWeldOperationValidator;

  public string WeldPointType => "WeldPointRevision";

  public bool IsWeldPointPrivate { get; private set; }

  public CApCreateWpTCLogic()
  {
    this.IsWeldPointPrivate = CApCreateWpTCLogic.IsWpConfiguredAsPrivate();
    ResourceManager resourceManager = new ResourceManager("DnProcessSimulateCommands.StringTable", this.GetType().Assembly);
    this.WeldContainerValidator = new CApCreateWpCommonValidator();
    this.WeldContainerValidator.AllowedTypes = new List<Type>()
    {
      typeof (TxCompoundPart)
    };
    this.WeldContainerValidator.ErrorMessage = resourceManager.GetString("WELD_CMD_INVALID_WELD_CONTAINER");
    this.WeldOperationValidator = new CApCreateWpCommonValidator();
    this.WeldOperationValidator.AllowedTypes = new List<Type>()
    {
      typeof (ITxWeldOperation)
    };
    this.WeldOperationValidator.ErrorMessage = resourceManager.GetString("WELD_CMD_INVALID_WELD_OPERATION");
    if (!this.IsWeldPointPrivate)
      this._CompositeWeldContainerValidator = new TxCompositeValidator(new object[2]
      {
        (object) this.WeldContainerValidator,
        (object) new TxObjectAssignmentValidator()
        {
          AssigneeType = this.WeldPointType
        }
      });
    else
      this._CompositeWeldContainerValidator = new TxCompositeValidator();
    if (!this.IsWeldPointPrivate)
      this._CompositeWeldOperationValidator = new TxCompositeValidator(new object[3]
      {
        (object) this.WeldOperationValidator,
        (object) new TxObjectAssignmentValidator()
        {
          AssigneeType = this.WeldPointType
        },
        (object) new TxObjectAccessValidator()
      });
    else
      this._CompositeWeldOperationValidator = new TxCompositeValidator(new object[2]
      {
        (object) this.WeldOperationValidator,
        (object) new TxObjectAccessValidator()
      });
  }

  public static TxPickProvider[] GetPickProviders()
  {
    // ISSUE: unable to decompile the method.
  }

  public static bool IsWpConfiguredAsPrivate()
  {
    bool flag = false;
    if (TxApplication.ActiveDocument.PlatformGlobalServicesProvider is ITxTcAnyGlobalServicesProvider servicesProvider && servicesProvider.IsPrivateObjectType("WeldPointRevision"))
      flag = true;
    return flag;
  }

  public bool IsDataValid(ITxObject weldContainer, ITxObject weldOperation)
  {
    bool flag = false;
    if ((this.IsWeldPointPrivate ? 1 : (weldContainer != null ? 1 : 0)) != 0 && weldOperation != null)
      flag = true;
    return flag;
  }

  public static string GetUniqueWPDisplayName()
  {
    return TxApplication.ActiveDocument.PhysicalRoot.GetUniqueDisplayName("wp");
  }

  public ITxObject GetSelectedWeldContainer()
  {
    ITxObject selectedWeldContainer = (ITxObject) null;
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    foreach (Type allowedType in this.WeldContainerValidator.AllowedTypes)
      txTypeFilter.AddIncludedType(allowedType);
    TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter);
    // ISSUE: explicit non-virtual call
    if (filteredItems != null && __nonvirtual (((Collection<ITxObject>) filteredItems).Count) > 0)
    {
      foreach (ITxObject itxObject in (Collection<ITxObject>) filteredItems)
      {
        string str;
        if (this._CompositeWeldContainerValidator.IsValidObject(itxObject, ref str))
        {
          selectedWeldContainer = itxObject;
          break;
        }
      }
    }
    return selectedWeldContainer;
  }

  public ITxObject GetSelectedWeldOperation()
  {
    ITxObject selectedWeldOperation = (ITxObject) null;
    TxTypeFilter txTypeFilter = new TxTypeFilter();
    foreach (Type allowedType in this.WeldOperationValidator.AllowedTypes)
      txTypeFilter.AddIncludedType(allowedType);
    TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter);
    // ISSUE: explicit non-virtual call
    if (filteredItems != null && __nonvirtual (((Collection<ITxObject>) filteredItems).Count) > 0)
    {
      foreach (ITxObject itxObject in (Collection<ITxObject>) filteredItems)
      {
        string str;
        if (this._CompositeWeldOperationValidator.IsValidObject(itxObject, ref str))
        {
          selectedWeldOperation = itxObject;
          break;
        }
      }
    }
    return selectedWeldOperation;
  }

  public void RunCreateWeldPointsMode(ITxObject weldOperation, ITxObject weldContainer)
  {
    TxObjectList txObjectList = new TxObjectList();
    if (weldOperation is ITxWeldOperation)
      ((Collection<ITxObject>) txObjectList).Add((ITxObject) (weldOperation as ITxWeldOperation));
    if (!this.IsWeldPointPrivate && weldContainer != null && weldContainer is TxCompoundPart)
      ((Collection<ITxObject>) txObjectList).Add((ITxObject) (weldContainer as TxCompoundPart));
    new TxCommandManager().ExecuteCommandByCommandProgId("GraphicViewerModes.ModeCreateWeldPoint.1", (object) txObjectList, false);
  }
}
